﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataEditor.DataLayer;

namespace DataEditor.ViewModels
{
    public class UnitItemViewModel : BaseDataItemViewModel
    {
        UNIT _model;

        #region Constructors

        public UnitItemViewModel(UNIT unitModel):base(unitModel.IsValid, unitModel.ValidFrom, unitModel.ValidTo, unitModel.ID)
        {
            _model = unitModel;
        }


        #endregion

        #region Properties

        public UNIT UnitModel
        {
            get
            {
                return _model;
            }
        }

        public String Name
        {
            get
            {
                return _model.NAME;
            }
            set
            {
                _model.NAME = value;
                NotifyOfPropertyChange(() => Name);
            }
        }

        public List<Int32> Prefixes
        {
            get
            {
                var prefixes = (from p in dataContext.UNIT_PREFIX
                                select p.ID).ToList<Int32>();
                return prefixes;
            }
        }

        public Int32 UnitPrefix_FK
        {
            get
            {
                return _model.UNIT_PREFIX_FK.HasValue ? _model.UNIT_PREFIX_FK.Value : 0;
            }
            set
            {
                _model.UNIT_PREFIX_FK = value;
                NotifyOfPropertyChange(() => UnitPrefix_FK);
            }
        }

        public Int32 UnitSymbol_FK
        {
            get
            {
                return _model.UNIT_SYMBOL_FK;
            }
            set
            {
                _model.UNIT_SYMBOL_FK = value;
                NotifyOfPropertyChange(() => UnitSymbol_FK);
            }
        }

        public List<Int32> Symbols
        {
            get
            {
                var prefixes = (from p in dataContext.UNIT_SYMBOL
                               select p.ID).ToList<Int32>();
                return prefixes;
            }
        }

        
        #endregion

    }
}
